import random
import time

from PyQt5.QtCore import QThread


# 创建一个QThread派生类用于运行信号发射,相当于就是在子线程
class SignalThread(QThread):
    ifStop = False

    def __init__(self, emitter, interval=1000):
        super().__init__()
        self.emitter = emitter
        self.interval = interval

    def set_excel_file(self, filename):
        self.filename = filename
        pass

    def run(self):
        self.emitter.emit_signal(f"start run......")
        while True:
            if self.ifStop:
                self.emitter.emit_signal(f"stop run......")
                break
            # 每隔一段时间发射信号
            timestamp = int(time.time())
            self.emitter.emit_signal(f"开始读取excel表{self.filename}中的第{timestamp}条数据......")
            time.sleep(1)
            self.emitter.emit_signal(f"exce{self.filename}l表中的第{timestamp}条数据执行完成.......")
            self.msleep(self.interval)
